#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QMessageBox>
#include <QDateTime>
#include <QDebug>

extern "C"{
#include "test/helloworld.h"
#include "test/gcc_note.h"
#include "stdio.h"
}


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    contactWin(NULL),netdiskWin(NULL),aboutDlg(NULL),featureWin(NULL),musicPlayerWin(NULL),diaryWin(NULL){
    ui->setupUi(this);
    sayHello();
    sayWorld();
    printGccNote();

    sbTime=new QLabel;
    //    sbTime->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));
    sbTime->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
    statusBar()->addWidget(sbTime,1);
}

MainWindow::~MainWindow(){
    delete sbTime;
    delete contactWin;
    delete netdiskWin;
    delete aboutDlg;
    delete featureWin;
    delete musicPlayerWin;
    delete diaryWin;
    delete ui;
}

void MainWindow::on_actionContact_triggered(){
    if(contactWin==NULL)
        contactWin=new ContactMain(this);
    if(!contactWin->isVisible())
        contactWin->setVisible(true);
}

void MainWindow::on_actionAbout_triggered(){
    aboutDlg=new AboutDialog(this);
    aboutDlg->exec();
}

void MainWindow::on_actionExit_triggered(){
    QMessageBox messagebox;
    messagebox.setWindowTitle(tr("Exit"));
    messagebox.setText(tr("Confirm exit?"));
    messagebox.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
    messagebox.setDefaultButton(QMessageBox::No);
    messagebox.setWindowIcon(QIcon(":/Images/Icon"));
    switch(messagebox.exec()){
    case QMessageBox::Yes:
        qApp->quit();//OR QApplication::exit();
        break;
    default:
        break;
    }
}

void MainWindow::on_actionNetDisk_triggered(){
    if(netdiskWin==NULL)
        netdiskWin=new NetDiskMain(this);
    if(!netdiskWin->isVisible())
        netdiskWin->setVisible(true);
}

void MainWindow::on_actionLock_triggered(){

}

void MainWindow::on_actionLogout_triggered(){

}

void MainWindow::deleteWindow(QObject *yourself){
    if(yourself==netdiskWin){
        delete netdiskWin;
        netdiskWin=NULL;
    }else if(yourself==contactWin){
        delete contactWin;
        contactWin=NULL;
    }else if(yourself==aboutDlg){
        delete aboutDlg;
        aboutDlg=NULL;
    }
    else if(yourself==featureWin){
        delete featureWin;
        featureWin=NULL;
    }
}

void MainWindow::on_actionFeatures_triggered(){
    if(featureWin==NULL)
        featureWin=new FeatureMain(this);
    if(!featureWin->isVisible())
        featureWin->setVisible(true);
}

void MainWindow::on_actionMusicPlayer_triggered(){
    if(musicPlayerWin==NULL)
        musicPlayerWin=new MusicPlayerMain(this);
    if(!musicPlayerWin->isVisible())
        musicPlayerWin->setVisible(true);
}

void MainWindow::on_actionDiary_triggered(){
    if(diaryWin==NULL)
        diaryWin=new DiaryMain(this);
    if(!diaryWin->isVisible())
        diaryWin->setVisible(true);
}
